package com.acme.exchange.domain.order;

import java.util.Comparator;

public class OrderCompare implements Comparator<Order> {

	@Override
	public int compare(Order arg0, Order arg1) {
		java.math.BigDecimal a0Price, a1Price;

		a0Price = arg0.getPrice();
		a1Price = arg1.getPrice();
		int result = a0Price.compareTo(a1Price);
		if (result != 0) {
			return result;
		}
		// a0.price = a1.price
		if (arg0.getOpType().equals(arg1.getOpType())) { //if we add to orderBook
			if (arg0.getOderID() < arg1.getOderID()) {
				// consider that (ordNum1 < ordNum2) is consequent from (t1 <
				// t2)
				return -1;
			}
			return 1;
		}
		return 0;
	}

}
